﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Sita.Entities.DeliveryNote>" %>

<%@ Import Namespace="Sita.Presentation.Resources.DeliveryNote" %>
<asp:Content ID="Content2" ContentPlaceHolderID="HeaderContent" runat="server">
    <link rel="stylesheet" href="../../Content/Styles/WOStyle.css" type="text/css" media="screen"
        title="default" />
    <script src="../../Scripts/Shared/jQuery/ui/i18n/jquery.ui.datePicker-es.js" type="text/javascript"></script>
    <script src="<%: Html.AuthenticateUrl("~/Scripts/DeliveryNote/Validation.js") %>"
        type="text/javascript"></script>
    <script type="text/javascript">
        AlreadyExistsMessage = "<%: Index.AlreadyExists %>";
        ExceedesStockMessage = "<%: Index.ExceedesStock %>";
    </script>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

<div style="padding: 40px;">
<h1>Crear / Editar Remitos</h1>

    <div id="DeliveryNoteContent">
        <% Html.EnableClientValidation(); %>
        <% using (Ajax.BeginForm("CreateOrUpdate", "DeliveryNote",
           new AjaxOptions() { OnComplete = "submitCompleted", HttpMethod = "Post" }, new { id = "DeliveryNoteForm" }))
           {%>
        <% var creationDate = "";
           if (Model.CreationDate != null)
           {
               creationDate = Model.CreationDate.Day + "/" + Model.CreationDate.Month + "/" + Model.CreationDate.Year;
           }%>
        <%: Html.ValidationSummary(true)%>
        <center>
            <%: Html.HiddenFor(model => model.DeliveryNoteID)%>
            <%: Html.HiddenFor(model => model.BusinessUnitID)%>
            <%: Html.HiddenFor(model=>model.CustomerID) %>
            <div class="form-modulo">
                <div class="form-modulo-title">
                   Cliente 
                </div>
                <div class="form-modulo-box">
                    <%if (Model.CustomerID == 0)
                      { %>
                    <input type="text" id="CompanyName" style="width: 100px; height: 20px;" value="<%:ViewData["CustomerName"]%>" />
                    <%}
                      else
                      { %>
                    <label>
                        <%:ViewData["CustomerName"]%></label>
                    <%} %>
                </div>
            </div>
            <div class="form-modulo">
                <div class="form-modulo-title">
                    Fecha
                </div>
                <div class="form-modulo-box">
                    <input type="text" id="_creationDate" readonly="readonly" onkeydown="preventBackspace();"
                        value="<%: creationDate %>" />
                    <%: Html.HiddenFor(model => model.CreationDate)%>
                </div>
            </div>
            <div class="form-modulo" style="margin-bottom: 30px;">
                <div class="form-modulo-title">
                    <%: Index.AddReplacement %>
                </div>
                <div class="form-modulo-box" style="width: 310px">
                    <input type="text" id="ItemName" /><input type="hidden" id="ItemID" /><input type="button"
                        id="AddItem" value="Agregar producto" class = "btn btn-lg btn-primary" style="float:right" />
                </div>
            </div>
            <div id="Details">
                <table style="width: 100%;">
                    <thead style="border-bottom: 1px solid black; border-top: 1px solid black; background: whitesmoke;">
                        <tr>
                            <td colspan="5">
                                &nbsp;
                            </td>
                        </tr>
                        <tr>
                            <th>
                                &nbsp;
                            </th>
                            <th style="width: 50px">
                                <%: Index.Quantity %>
                            </th>
                            <th>
                                <%: Index.Name %>
                            </th>
                            <th>
                                <%: Index.UnitPrice %>
                            </th>
                            <th>
                                <%: Index.TotalPrice %>
                            </th>
                        </tr>
                        <tr>
                            <td colspan="5">
                                &nbsp;
                            </td>
                        </tr>
                    </thead>
                    <tbody id="ItemTable">
                        <tr>
                            <td colspan="5">
                                &nbsp;
                            </td>
                        </tr>
                        <%--AGREGAR ITEMS PREEXISTENTES--%>
                        <% var columnIndex = 0;
                           decimal totalPrice = 0;
                           foreach (Sita.Entities.DeliveryNoteReplacement item in Model.DeliveryNoteReplacements)
                           { %>
                        <tr id="rowItem_<%: columnIndex%>" class="detail">
                            <td>
                                <input type="hidden" value="<%: item.ReplacementID %>" id="ReplacementID_<%: columnIndex%>" />
                                <input type="hidden" value="<%: item.Replacement.Stock %>" id="Stock_<%: columnIndex%>" />
                                <img src="../../Content/Images/cross.png" onclick="DeleteRow(<%: columnIndex%>)" />
                            </td>
                            <td>
                                <input type="text" value="<%:item.Quantity %>" id="Quantity_<%: columnIndex%>" onchange="ModifyPrice(<%: columnIndex%>)" />
                            </td>
                            <td>
                                <%:item.Replacement.Name%>
                            </td>
                            <td>
                                <input type="text" value="<%:item.UnitPrice %>" id="UnitPrice_<%: columnIndex%>"
                                    onchange="UnitPrice_Change(this, <%: columnIndex%>)" />
                            </td>
                            <td>
                                <input readonly="readonly" type="text" id="TotalPrice_<%: columnIndex%>" value="<%:item.TotalPrice %>" />
                            </td>
                        </tr>
                        <%columnIndex++;
                          totalPrice += item.TotalPrice;
                           }%>
                        <%--FIN AGREGADO DE ITEMS--%>
                    </tbody>
                    <tfoot style="border-top: 1px solid black; font-weight: bold;">
                        <tr>
                            <td colspan="5" align="left">
                                &nbsp;
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3">
                                &nbsp;
                            </td>
                            <td style="text-align: right;">
                                <%: Index.Total %>
                            </td>
                            <td>
                                <label id="DeliveryNote_Total_Price">
                                    <%: totalPrice%>
                                </label>
                            </td>
                        </tr>
                    </tfoot>
                </table>
            </div>
            <div class="form-modulo">
                <div class="form-modulo-boton" style= "float:right;">
                    <input type="submit" class="btn btn-lg btn-primary" value="Guardar" id="Save" />
                    <input type="button" class="btn btn-lg btn-secondary" value="Cancelar" id="Cancel" />
                </div>
            </div>
            <div class="form-separador" />
            <div class="form-clear" />
        </center>
        <script type="text/javascript">
        $(function () {
            ValidateForm();
        });
        columnIndex = <%: columnIndex%>;
        $("#Module_9ul").removeClass("select").addClass("current");
        </script>
        <%} %>
    </div>

    </div>
</asp:Content>
